package com.sinheldrin.musicplayer.main
{
	import com.sinheldrin.musicplayer.library.Library;
	import com.sinheldrin.musicplayer.music.Music;
	import com.sinheldrin.musicplayer.player.PlayerController;

	public class MainController
	{
		public function MainController(mainView:MainView)
		{
			_view = mainView;
			
			_player = new PlayerController(view.playerView);
			_library = new Library();
		}
		
		public function init():void
		{
			_library.load();
			_player.init();
		}
		
		private var _view:MainView = null;
		public function get view():MainView
		{
			return _view;
		}
		
		private var _player:PlayerController = null;
		
		private var _library:Library = null;
		
		public function readLibrary():void
		{
			_player.setPlaylist(_library.toPlaylist());
		}
		
		public function saveLibrary():void
		{
			_library.save();
		}
		
		public function newMusic(music:Music):void
		{
			_library.addNewMusic(music);
			_player.model.currentPlaylist.addMusic(music);
		}
	}
}